﻿<%@ Page Language="C#" %>

<%@ Import Namespace="System.Data.SqlClient" %>
<%        
    string ServerName = "测试";
    string DBIP = "-"; //　-　表示没有数据库服务器
    string DBName = "";
    string DBUser = "";
    string DBPassword = "";
    string conn = string.Format(@"Data Source={0};Initial Catalog={1};Persist Security Info=True;
                         User Instance=False;User ID={2};Password={3};MultipleActiveResultSets=true"
       , DBIP
       , DBName
       , DBUser
       , DBPassword);


    string message = "NoSql";
    if (DBIP != "-")
    {
        using (SqlConnection _conn = new SqlConnection(conn))
        {
            using (SqlCommand comm = new SqlCommand("SELECT COUNT(1)  FROM sys.tables", _conn))
            {
                try
                {
                    _conn.Open();
                    comm.ExecuteReader();
                    message = "OK";
                    _conn.Close();
                    _conn.Dispose();
                }
                catch (Exception)
                {
                    message = "Fail";
                }

            }
        }
    }


    string callback = Request["jsonpcallback"];
    Response.ContentType = "application/x-javascript";
    string str = callback + "({" + string.Format("\'ServerName\':\'{0}\', \'ServerIP\':\'{1}\',\'IISMessage\':\'{2}\',\'DBMessage\':\'{3}\'", ServerName, Request.ServerVariables["LOCAL_ADDR"].ToString(), "OK", message) + "})";
    Response.Write(str);
  
%>